package com.abei.gas.service.Impl;

import com.abei.gas.entity.Admin;
import com.abei.gas.mapper.AdminMapper;
import com.abei.gas.service.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminMapper adminMapper;

    /*
    * 管理员登录
    * */
    @Override
    public Integer Login(String username, String password) {
        int res=0;//登录成功
        Admin Admin = adminMapper.selectById(username);
        if(Admin==null) {
            res=1;//提示用户名不存在
        } else if(!Admin.getPassword().equals(password)) {
            res=2;//提示密码错误
        }
        return res;
    }

    /*
     * 管理员注册
     * */
    @Override
    public Integer insert(String username, String password) {
        Admin n=new Admin();
        n.setUsername(username);
        n.setPassword(password);
        adminMapper.insert(n);
        return 1;
    }

    /*
    * 检索管理员是否存在
    * */
    @Override
    public Integer Select(String username) {
        int res=0;//用户名已经存在
        Admin admin = adminMapper.selectById(username);
        if(admin==null)
            res=1;//表示可以注册
        return res;
    }

}
